<template>
  <div>
    <button @click="logIn">登录</button>
    <p>{{hint}}</p>
  </div>
</template>

<script>
export default {
  name: 'Login',
  props: {

  },
  data() {
    return {
      hint: ''
    };
  },
  computed: {

  },
  created() {
  },
  mounted() {

  },
  methods: {
    logIn() {
      this.hint = '正在登录中....'
      this.$store.dispatch('logIn').then((response) => {
        if (this.$store.state.login.roles.length > 0) {
          this.hint = '登录完成'
          this.$router.push('/')
          return
        }
        this.$store.dispatch('FETCH_USERINFO').then((res) => {
          this.hint = '登录完成'
          this.$router.push('/')
        })
      })

    }
  },
  watch: {

  },
  components: {

  },
};
</script>